<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;

class DelFileAfterDownload implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $filePaths;

    /**
     * 文件下载成功，5分钟后删除
     */
    public function __construct($filePaths)
    {
        $this->filePaths = $filePaths;
    }

    /**
     * 执行业务控制器
     * 用来执行延时任务的具体业务逻辑
     * 这里删除文件使用 Storage 可以，File 不行，原因未知
     * Storage::delete('/public/excels/南郑特大桥案卷序号【51~100】085220.zip');
     * Storage::deleteDirectory('/public/excels/南郑特大桥案卷序号【51~100】085220');
     */
    public function handle()
    {
        $filePaths = $this->filePaths;
        Storage::delete($filePaths['origin_pdf']); //删除PDF源文件
        Storage::deleteDirectory($filePaths['dir']); //删除分割后的文件夹
    }
}
